package com.molichuxing.services.infrastructure.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.HandoverMapper;
import com.molichuxing.services.infrastructure.dto.request.create.HandoverCreateDto;
import com.molichuxing.services.infrastructure.dto.request.modify.HandoverModifyDto;
import com.molichuxing.services.infrastructure.dto.response.HandoverDto;
import com.molichuxing.services.infrastructure.service.HandoverService;
import com.molichuxing.services.property.HandoverTypeEnum;

/**
 * 车辆交接单service
 * 
 * @author zoumingyu
 * @date 2019年10月26日
 *
 */
@Service("handoverService")
public class HandoverServiceImpl implements HandoverService {

	@Resource
	private HandoverMapper handoverMapper;

	/**
	 * 新增车辆交接信息
	 * 
	 * @param createDto
	 * @return
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
	public Boolean create(HandoverCreateDto createDto) {
		handoverMapper.create(Convert.toHandoverBean(createDto));
		return true;
	}

	/**
	 * 查询交接单信息
	 * 
	 * @param orderCode
	 *            订单号
	 * @param type
	 *            交接单类型
	 * @return
	 */
	@Override
	public HandoverDto getHandover(Long orderCode, HandoverTypeEnum type) {
		return Convert.toHandoverDto(handoverMapper.getHandoverByorderCode(orderCode, type.getValue()));
	}

	/**
	 * 修改车辆交接信息
	 * 
	 * @param modifyDto
	 * @return
	 */
	@Override
	public Boolean modify(HandoverModifyDto modifyDto) {
		if (handoverMapper.modify(Convert.toHandoverBean(modifyDto)) > 0) {
			return true;
		}
		return false;
	}

}
